export default {
	data() {
		return {
			//搜索关键字
			keyword: '',
			groupName: '',
			groupImg: '',
			text: '',
			value: 1,
			indexList: [],
			downList: [{
					iconPath: "home",
					selectedIconPath: "home-fill",
					text: '消息',
					customIcon: false,
					pagePath: '/pages/index/index'
				},
				{
					iconPath: "man-add",
					selectedIconPath: "man-add-fill",
					text: '添加',
					customIcon: false,
					pagePath: '/pages/add/add'
				},
				{
					iconPath: "account",
					selectedIconPath: "account-fill",
					text: '我的',
					customIcon: false,
					pagePath: '/pages/user/user'
				}
			],
			current: 0,
			startPage: 0,
			endPage: 10,
			show: false
		}
	},
	onLoad() {
		this.userId = uni.getStorageSync('userId');
	},
	methods: {
		async beforeSwitch(index) {
			console.log(index)
			switch (index) {
				case 0:
					uni.reLaunch({
						url: '/pages/index/index',
					});
					break;
				case 1:

					break;
				case 2:

					break;
			}
			return true;
		},
		//搜索群组
		search(e) {
			if (e == '') {
				return;
			}
			this.$request('/Group/queryGroupByKeyword', {
				// 传参参数名：参数值,如果没有，就不需要传
				"keyword": e,
				"startPage": this.startPage,
				"endPage": this.endPage
			}).then(res => {
				if (res.code == 200) {
					this.indexList = res.data;
				}
			})
		},
		//申请加群
		add(e) {
			this.$request('/User/userApplyGroup', {
				// 传参参数名：参数值,如果没有，就不需要传
				"userId": uni.getStorageSync('userId'),
				"groupId": e.id
			}).then(res => {
				if (res.code == 200) {
					uni.showToast({
						title: res.msg,
						icon:'none',
						duration: 2000
					});
				}
				else{
					uni.showToast({
						title: res.msg,
						icon:'none',
						duration: 2000
					});
				}
			})
		},
		//文件上传
		upload() {
			uni.chooseImage({
				success: (chooseImageRes) => {
					const tempFilePaths = chooseImageRes.tempFilePaths;
					const uploadTask = uni.uploadFile({
						url: this.$url + '/Upload/uploadFile',
						filePath: tempFilePaths[0],
						name: 'file',
						formData: {
							'type': 'head'
						},
						success: (uploadFileRes) => {
							var data = JSON.parse(uploadFileRes.data)
							if (data.code == 200) {
								this.groupImg = data.data.url;
							} else {
								//this.tip = '图片上传出错';
							}
						}
					});
				}
			});
		},
		//创建群组
		create() {
			let that = this;
			this.$request('/Group/insertGroup', {
				// 传参参数名：参数值,如果没有，就不需要传
				"userId": this.userId,
				"groupName": this.groupName,
				"groupImg": this.groupImg
			}).then(res => {
				if (res.code == 200) {
					
					that.show = false;
					uni.showToast({
						title: res.msg,
						icon:'none',
						duration: 2000
					});
				}
			})
		}
	}
}
